Implementing Data Drill-Down
You want the user to be able to click a part and see its details appear to the right in the interface. Build this using a two-step process:
- Code the method to populate the detail TextBoxes when the user clicks in the ListBox.
- Tell Macromedia Flash to associate a ListBox click with the particular method.
Setting a Change or Click Handler. The setClickHandler()or setChangeHandler()methods
specify a handler function to call when the user releases the mouse
button. Each has one required and one optional parameter. The syntax
is as follows:
my_pb.setClickHandler(functionName, [location])
The functionName is the name of the handler function to execute. The location is a path to an object that contains the function. If no path is specified, the function must be in the main Timeline and not tied to any particular object. In this tutorial, you continue to follow the best practice of associating all methods with an object, so you specify the optional parameter.
Exercise 3
In this exercise, you will build a method to fill the TextBoxes and hide the PushButton and ComboBox, and set up a default selection.
- In devnet.fla, move to the top of the object methods section.
-
Create a skeleton for the
fillTextBoxes()method that attaches to the parts_lb object, as follows:parts_lb.fillTextBoxes=function(){ } -
Inside the method, fill the following TextBoxes with the corresponding values from the data portion of the selected item:
- name_txt.text:
parts_lb.getSelectedItem().data.name - type_txt.text:
parts_lb.getSelectedItem().data.partType - price_txt.text:
parts_lb.getSelectedItem().data.price - desc_txt.text:
parts_lb.getSelectedItem().data.description
- name_txt.text:
-
Ensure your method appears as shown here:
parts_lb.fillTextBoxes=function() { name_txt.text=parts_lb.getSelectedItem().data.name; type_txt.text=parts_lb.getSelectedItem().data.partType; price_txt.text=parts_lb.getSelectedItem().data.price; desc_txt.text=parts_lb.getSelectedItem().data.description; } -
In the event handler assignment section, associate
fillTextBoxeswith a change in the ListBox, using thesetChangeHandler()method. The resulting code should appear as follows:parts_lb.setChangeHandler("fillTextBoxes",parts_lb); - Save the document and test the movie. When you click a part, you should see the details appear. Notice that the ComboBox covers the part type and that the Add New Part button appears, although it shouldn't at this point. Also, notice that the object does not default automatically to a part.
-
To hide the PushButton and ComboBox problem, go to the top of the run at once commands section and set both components' _visible properties to false, as shown here:
types_cb._visible=false; addPart_pb._visible=false;
- To get the first item as a default selection, return
to the partResponder.onResult method in the object methods section. Add another line of code to simulate the user clicking on the first
item in the ListBox. Use the
setSelectedIndex()method and remember the ListBox is zero-indexed. -
Ensure your method appears as shown:
partResponder.onResult=function(parts_rs) { DataGlue.bindFormatFunction(parts_lb,parts_rs,binder); parts_lb.setSelectedIndex(0); } - Save the document and test the movie. You should now see that the ComboBox and PushButton have disappeared and that the first part's details appear. Click other parts to see their details.
Submit feedback on our tutorials, articles, and sample applications.